﻿if (!window.top.ngW8) {
    window.top.ngW8 = {};
}
if (!window.top.ngW8.systems) {
    window.top.ngW8.systems = {};
}
if (!window.top.ngW8.systems.components) {
    window.top.ngW8.systems.components = {};
}
window.top.ngW8.systems.components.view = function ($tmp) {
    $tmp.$stack = [];
    if ($tmp.$a.masterView) {
        ngW8.$("$template")($tmp.$a.path, $tmp.$a.masterView)
            .$whenComplete(function (sender) {
                sender.element.appendTo($($tmp.$e[0])[0]);
            })
        .$done($tmp.$s.$parent)
    }
    else {
        $tmp.$a.$observe("path", function (value) {

            ngW8.$("$page")(value).$whenComplete(function (sender) {
                if ($tmp.$currentPage) {
                    $tmp.$currentPage.$scope.$destroy();
                    $tmp.$currentPage.$element.remove();

                }
                $tmp.$currentPage = {
                    $element: sender.element,
                    $scope: sender.scope
                };
                $tmp.$stack.push(value);
                sender.element.appendTo($($tmp.$e[0])[0]);
            })
            .$whenError(function (sender) {
                $($tmp.$e[0]).html(sender.$error.data);
                if ($tmp.$masterElement) {

                }
            }).$apply($tmp.$s);
        });
    }
};